package cn.iocoder.yudao.module.crm.dal.mysql.tasktype;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.module.crm.controller.admin.tasktype.vo.TaskTypePageReqVO;
import cn.iocoder.yudao.module.crm.controller.admin.tasktype.vo.tasktypeassignee.TaskTypeAssigneeDetail;
import cn.iocoder.yudao.module.crm.dal.dataobject.tasktype.TaskTypeAssigneeDO;
import cn.iocoder.yudao.module.crm.dal.dataobject.tasktype.TaskTypeDO;
import org.apache.ibatis.annotations.Mapper;

import java.util.List;

/**
 * CRM 任务单类型处理人关联 Mapper
 *
 * @author 广州氪量
 */
@Mapper
public interface TaskTypeAssigneeMapper extends BaseMapperX<TaskTypeAssigneeDO> {
    default long countByTaskTypeId(Long taskTypeId) {
        return selectCount(new LambdaQueryWrapperX<TaskTypeAssigneeDO>()
                .eqIfPresent(TaskTypeAssigneeDO::getTaskTypeId, taskTypeId));
    }

    default List<TaskTypeAssigneeDO> getByTaskTypeId(Long id){
        return selectList(new LambdaQueryWrapperX<TaskTypeAssigneeDO>()
                .eq(TaskTypeAssigneeDO::getTaskTypeId, id));
    }

    default void insertBatchByTaskTypeId(List<TaskTypeAssigneeDetail> autoIssue, Long taskTypeId){
        autoIssue.forEach(item -> {
            TaskTypeAssigneeDO taskTypeAssigneeDO = new TaskTypeAssigneeDO();
            taskTypeAssigneeDO.setTaskTypeId(taskTypeId);
            taskTypeAssigneeDO.setUserId(item.getUserId());
            taskTypeAssigneeDO.setMonthlyIssueTime(item.getMonthlyIssueTime());
            insert(taskTypeAssigneeDO);
        });
    }

    default void deleteBatchByTaskTypeId(Long taskTypeId){
        delete(new LambdaQueryWrapperX<TaskTypeAssigneeDO>()
                .eq(TaskTypeAssigneeDO::getTaskTypeId, taskTypeId));
    }
}